package com.uoko.demo.controller;

import com.uoko.demo.domain.entity.UserEntity;
import com.uoko.demo.service.UserService;
import com.uoko.demo.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * @author shaohua
 * @email shaohua@uoko.com
 * @date 2018-06-12 16:12:25
 */
@RestController
@RequestMapping("demo/user")
public class UserController {
    @Autowired
    private UserService userService;


    /**
     * 信息
     */
    @GetMapping("/info/{userId}")
    public R info(@PathVariable("userId") Integer userId) {
        UserEntity user = userService.selectById(userId);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserEntity user) {
        userService.insert(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody UserEntity user) {
        userService.updateAllColumnById(user);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] userIds) {
        userService.deleteBatchIds(Arrays.asList(userIds));

        return R.ok();
    }

}
